/*
 GPNavigationBarViewController.h
 Date Created: February 20, 2010
 
 Author: Karol Krizka <kkrizka@gmail.com>
 
 Copyright (C) 2010 Green-Power
 
 URL: http://code.google.com/p/green-power
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 $Id$
 */

#import "GPNavigationBarViewController.h"

@implementation GPNavigationBarViewController

@synthesize navigation;
@synthesize subviewController;

- (GPNavigationBarViewController *)init {
  self=[super init];
  if( self ) {
    navigation=[[UINavigationItem alloc] initWithTitle:@"Title"];
  }
  return self;
}

// Setup the navigation bar with the navigation item
- (void)viewDidLoad {
  [super viewDidLoad];
  
  [navigationBar pushNavigationItem:self.navigation animated:NO];
}

- (void)setSubviewController:(UIViewController *)newSubviewController {
  if(subviewController) { // Remove any previous subviews
    [subviewController.view removeFromSuperview];
    [subviewController release];
  }
  subviewController=newSubviewController;
  [subviewController retain];
  
  CGRect viewFrame=self.view.frame;
  CGRect navigationBarFrame=navigationBar.frame;
  CGRect subviewFrame=CGRectMake(0,
                                 navigationBarFrame.size.height,
                                 viewFrame.size.width,
                                 viewFrame.size.height-navigationBarFrame.size.height);
  subviewController.view.frame=subviewFrame;
  [self.view addSubview:subviewController.view];
  [self.view sendSubviewToBack:subviewController.view];
}

- (void)dealloc {
  [navigationBar release];
  [navigation release];
  [subviewController release];
  
  [super dealloc];
}


@end
